package com.zx.controller;

import com.zx.common.ResponseCode;
import com.zx.entity.User;
import com.zx.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.thymeleaf.util.StringUtils;
import javax.servlet.http.HttpSession;
import java.util.Map;


@Controller
@RequestMapping("/edit")
public class EdPasswordController {
    @Autowired
    private UserRepository repository;

    @GetMapping("/list")
    public ModelAndView list(HttpSession session,
                             Map<String,Object> map){
        String username = (String) session.getAttribute("loginUser");
        if(StringUtils.isEmpty(username)){
            map.put("msg", ResponseCode.LOGIN_ERROR.getDesc());
            map.put("url","/foodshare/user/login");
            return new ModelAndView("common/error",map);
        }
        User user = repository.findByUsername(username);
        map.put("user",user);
        return new ModelAndView("edpassword/list",map);
    }
}
